package com.sz.app.customer.api.system;

import com.sz.biz.app.web.BaseController;
import com.sz.biz.common.constants.MessagesCodes;
import com.sz.biz.common.customer.service.CustomerAuthorizationService;
import com.sz.common.base.dto.ResultDto;
import com.sz.common.core.system.dto.MenuPermissionDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Function: 授权controller <br>
 * Author: qiankun <br>
 * Date: 2017-05-22 14:24:46
 */

@RestController
@RequestMapping("${api}/u/auth")
@Api(description = " ", tags = "006、授权操作")
public class AuthorizationController extends BaseController {

    @Autowired
    private CustomerAuthorizationService service;

    @RequestMapping(value = "menuandpermission/{cusUserId}", method = RequestMethod.POST)
    @ApiOperation(value = "客户菜单&资源授权", notes = "给某个客户进行菜单&资源授权<br>权限：")
    public ResultDto saveMenuAndPermissionAuth(@PathVariable Integer cusUserId,
                                               @RequestBody List<MenuPermissionDto> menuPermissionDtos) {
        if (menuPermissionDtos != null) {
            service.saveCusUserIdAndMenuAndPermission(menuPermissionDtos, cusUserId);
        }
        ResultDto resultDto = getOperateSuccessDto(MessagesCodes.SUCCESS_AUTH_ROLE_SAVE_MESSAGE);
        return resultDto;
    }
}
